package org.unisannio.interactive;



import android.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class AddressListActivity extends ListActivity {
	
	AddressArrayAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		ArrayAdapter<Address> adapter=new ArrayAdapter<Address>(this, R.layout.activity_list_item, CommunicationTestActivity.indirizzi);
		AddressArrayAdapter adapter=new AddressArrayAdapter(this,R.layout.activity_list_item,CommunicationTestActivity.indirizzi);
		setListAdapter(adapter);
		ListView lv= getListView();
		lv.setTextFilterEnabled(true);
		
		lv.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				Bundle bundle = new Bundle();
				bundle.putString("peerAddress", ((TextView) view).getText().toString());
				
				Intent myIntent=new Intent();
				myIntent.putExtras(bundle);
				setResult(RESULT_OK, myIntent);
				finish();
			}
		});
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		setResult(RESULT_OK,null);
	}
	
//	@Override
//	protected void onResume() {
//		super.onResume();
//		adapter.clear();
//		adapter=new AddressArrayAdapter(this,R.layout.activity_list_item,CommunicationTestActivity.indirizzi);
//		setListAdapter(adapter);
//	}

}
